﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using Zzva.Common;


namespace Zzva.UIWin
{
    public  partial class TFrmDialBase : Form
    {

        //объявляем  объект делегата
        public event EventHandler EventReady;
        protected bool mvarFlgChanch;
        
        
        public TFrmDialBase()
        {
            InitializeComponent();
            mvarFlgChanch = false;
        }


        private void CancelWithCheckChanch()
        {


            try
            {

                if (mvarFlgChanch == true)
                {

                    string caption = "Выполнена корректировка!";
                    string message = "Сохранить изменения?";
                    MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel;
                    DialogResult result = MessageBox.Show(message, caption, buttons);

                    switch (result)
                    {
                        case DialogResult.Yes:
                            Ready();
                            break;
                        case DialogResult.Cancel:
                            
                            break;
                        case DialogResult.No:
                            Cancel();
                            break;
                        default: throw (new CommonException("Нет ответа диалога"));
                    }

                }
                else{Cancel();}

            }

            catch (Exception e){MessageBox.Show(e.Message);}
            finally { }

        }







        protected void FireEventReady(EventArgs pEventArgs)
        {
            try
            {
                if (EventReady != null) EventReady(this, pEventArgs);

            }

            catch (Exception e) { throw e; }
            finally { }
        }



        protected virtual void Ready()
        {
            try
            {
                FireEventReady(EventArgs.Empty);
                this.Close();
            }

            catch (Exception e) { MessageBox.Show(e.Message); }
            finally { }
        }


        private void cmdReady_Click(object sender, EventArgs e)
        {
            Ready();
 
        }







        private void cmdCancel_Click(object sender, EventArgs e)
        {

            //''Cancel();
            CancelWithCheckChanch();
        }

        private void Cancel()
        {
            this.Close();
        }




    }
}
